<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>comment管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }

        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理
            <small>comment管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>comment管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true">
                    <el-form-item label="商品spuId">
                        <el-input v-model="searchMap.spuId" placeholder="商品spuId" class="filter-item"></el-input>
                    </el-form-item>

                    <el-form-item label="评价">
                        <el-select v-model="searchMap.evaluationRating" @change="fetchData()" placeholder="请选择">
                            <el-option
                                    v-for="item in options1"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="回复状态">
                        <el-select v-model="searchMap.isSuperadditionid" @change="fetchData()" placeholder="请选择">
                            <el-option
                                    v-for="item in options2"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    </el-form-item>
                    <el-form-item label="用户名">
                        <el-input v-model="searchMap.username" placeholder="用户名" class="filter-item"></el-input>
                    </el-form-item>


                    <el-button class="dalfBut" @click="fetchData()">查询</el-button>
                </el-form>
            </div>

            <el-table :data="tableData" border style="width: 100%">
                <el-table-column prop="id" label="评论id" width="120"></el-table-column>
                <el-table-column prop="spuId" label="spuid" width="120"></el-table-column>
                <el-table-column prop="skuId" label="skuid" width="120"></el-table-column>
                <el-table-column prop="evaluationRating" label="评价" width="100"></el-table-column>
                <el-table-column prop="createTime" label="评论创建时间" width="180"></el-table-column>
                <el-table-column prop="username" label="用户名" width="100"></el-table-column>
                <el-table-column plabel="是否显示" width="80">
                    <template slot-scope="scope">
                        <el-switch @change="isShow(scope.row.id,scope.row.isShow)"
                                v-model=scope.row.isShow
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value='1'
                                inactive-value='0'>
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.isSuperadditionid==0"
                                   @click="edit(scope.row.id)"
                                   size="mini" type="primary" size="small">回复
                        </el-button>
                        <el-button v-if="scope.row.isSuperadditionid==1"
                                   @click="edit(scope.row.id),xxx(scope.row.id)"
                                   size="mini" type="success" size="small">查看
                        </el-button>
                        <el-button @click="dele(scope.row.id)" size="mini" type="danger" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="fetchData"
                        @current-change="fetchData"
                        :current-page.sync="currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <div class="add-form">
                <!--弹出窗口-->
                <el-dialog title="查看" :visible.sync="formVisible">
                    <el-form label-width="80px">
                        <el-form-item label="商品规格">
                            <el-input v-model="pojo.spec" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="用户名">
                            <el-input v-model="pojo.username" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="评价">
                            <el-input v-model="pojo.userEvaluation" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="文字评论">
                            <el-input v-model="pojo.commentContent" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item v-if="pojo.isSuperadditionid!=0" label="回复内容">
                            <el-input v-model="input2"  :disabled="true"></el-input>
                        </el-form-item>

                        <el-form-item v-if="pojo.isSuperadditionid==0" label="回复内容">
                            <el-input v-model="input" placeholder="请输入内容"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button v-if="pojo.isSuperadditionid==0" type="primary" @click="formVisible = false,reply(pojo.id,input)">回复</el-button>
                            <el-button @click="formVisible = false">关闭</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,
                input: '',
                input2: '',
                options1: [
                    {
                        value: '',
                        label: '全部'
                    }, {
                        value: '0',
                        label: '差评'
                    }, {
                        value: '1',
                        label: '中评'
                    }, {
                        value: '2',
                        label: '好评'
                    }],
                options2: [
                    {
                        value: '',
                        label: '全部'
                    }, {
                        value: '0',
                        label: '未回复'
                    }, {
                        value: '1',
                        label: '已回复'
                    }],
            }
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/comment/findPage.do?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                    for (i = 0; i < this.tableData.length; i++) {
                        if (this.tableData[i].evaluationRating == '0') {
                            this.tableData[i].evaluationRating = '差评';
                        } else if (this.tableData[i].evaluationRating == '1') {
                            this.tableData[i].evaluationRating = '中评';
                        } else {
                            this.tableData[i].evaluationRating = '好评';
                        }
                    }
                });
            },
            save() {
                axios.post(`/comment/${this.pojo.id == null ? 'add' : 'update'}.do`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                    input:''
                });
            },
            edit(id) {
                this.formVisible = true; // 打开窗口
                // 调用查询
                axios.get(`/comment/findById.do?id=${id}`).then(response => {
                    this.pojo = response.data;
                });
            },
            xxx(parentId){
                axios.get(`/commentAdmin/findByParentId.do?id=${parentId}`).then(response=>{
                    this.input2=response.data.content;
                })
            },
            reply(id, content) {
                axios.get(`/commentAdmin/add.do?id=${id}&content=${content}`).then(response => {
                    this.fetchData(); //刷新列表
                })
            },
            dele(id) {
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/comment/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })
            },
            isShow(id,isShow){
                axios.get(`/comment/isShow.do?id=${id}&isShow=${isShow}`).then(response=>{

                })
            }

        }
    })
</script>
</html>
